package com.ruoyi.web.controller.qsng;

import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.qsng.domain.KNotice;
import com.ruoyi.qsng.service.IKNoticeService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 通知公告Controller
 *
 * @author kanglou
 * @date 2023-06-07
 */
@RestController
@RequestMapping("/qsng/notice")
@Api(tags = "pc--通知公告Controller")
public class KNoticeController extends BaseController {
    @Autowired
    private IKNoticeService kNoticeService;

    /**
     * 查询通知公告列表
     */
    @PreAuthorize("@ss.hasPermi('qsng:notice:list')")
    @GetMapping("/list")
    @ApiOperation(value = "查询通知公告列表")
    public TableDataInfo list(KNotice kNotice) {
        startPage();
        List<KNotice> list = kNoticeService.selectKNoticeList(kNotice);
        return getDataTable(list);
    }

    /**
     * 导出通知公告列表
     */
    @PreAuthorize("@ss.hasPermi('qsng:notice:export')")
    @Log(title = "通知公告", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ApiOperation(value = "导出通知公告列表")
    public void export(HttpServletResponse response, KNotice kNotice) {
        List<KNotice> list = kNoticeService.selectKNoticeList(kNotice);
        ExcelUtil<KNotice> util = new ExcelUtil<KNotice>(KNotice.class);
        util.exportExcel(response, list, "通知公告数据");
    }

    /**
     * 获取通知公告详细信息
     */
    @PreAuthorize("@ss.hasPermi('qsng:notice:query')")
    @GetMapping(value = "/{id}")
    @ApiOperation(value = "获取通知公告详细信息")
    public AjaxResult getInfo(@PathVariable("id") String id) {
        return success(kNoticeService.selectKNoticeById(id));
    }

    /**
     * 新增通知公告
     */
    @PreAuthorize("@ss.hasPermi('qsng:notice:add')")
    @Log(title = "通知公告", businessType = BusinessType.INSERT)
    @PostMapping
    @ApiOperation(value = "新增通知公告")
    public AjaxResult add(@RequestBody KNotice kNotice) {
        return toAjax(kNoticeService.insertKNotice(kNotice));
    }

    /**
     * 修改通知公告
     */
    @PreAuthorize("@ss.hasPermi('qsng:notice:edit')")
    @Log(title = "通知公告", businessType = BusinessType.UPDATE)
    @PutMapping
    @ApiOperation(value = "修改通知公告")
    public AjaxResult edit(@RequestBody KNotice kNotice) {
        return toAjax(kNoticeService.updateKNotice(kNotice));
    }

    /**
     * 删除通知公告
     */
    @PreAuthorize("@ss.hasPermi('qsng:notice:remove')")
    @Log(title = "通知公告", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    @ApiOperation(value = "删除通知公告")
    public AjaxResult remove(@PathVariable String[] ids) {
        return toAjax(kNoticeService.deleteKNoticeByIds(ids));
    }
}
